#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pcap/pcap.h>
int main(int argc, char **argv)
{
	pcap_t *handle;
	struct pcap_file_header pcapfh;	
	struct pcap_pkthdr pkthdr;
	u_char *pktdata;
	char error[100];
	struct pcap_stat pcap_info;
	int pktnum = 0;
	printf("filename is:%s\n", argv[1]);
	if((handle=pcap_open_offline(argv[1] ,error))==NULL)  //打开文件
    	{
        	printf("%s\n",error);
        	return 0;
	}
	pcap_stats(handle, &pcap_info);
	pktnum = pcap_info.ps_recv;
	while(1) {
		pktdata = pcap_next(handle, &pkthdr);
		if (pkthdr.len && pktdata == NULL)
			break;
	printf("caplen:%d\n, len:%d\n, time of sec:%ul\n, time of usec:%ul\n", pkthdr.caplen, pkthdr.len, pkthdr.ts.tv_sec, pkthdr.ts.tv_usec);
	printf("user data:%s\n", pktdata);
	}
	
	printf("caplen:%d\n, len:%d\n, time of sec:%ul\n, time of usec:%ul\n", pkthdr.caplen, pkthdr.len, pkthdr.ts.tv_sec, pkthdr.ts.tv_usec);
	
	printf("user data:%s\n", pktdata);
	
	printf("recv pkt num is:%d\n", pktnum);
	return 0;
}
